home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / games / sokosrc.zoo / showscre.c < prev    next >
C/C++ Source or Header  |  1991-01-26  |  3KB  |  132 lines

  1. #include <curses.h>
  2. #include "sokoban.h"
  3.  
  4. extern short rows, cols, level, moves, pushes, packets, savepack;
  5. extern char map[MAXROW+1][MAXCOL+1];
  6.  
  7. #if ATARIST
  8. #define input_off()
  9. input_on()    /* Clear the input buffer */
  10. {
  11.     while (Cconis()) Cnecin();
  12. }
  13. #else
  14. #define input_off() raw()
  15. #define input_on() noraw()
  16. #endif
  17.  
  18. showscreen() {
  19.  
  20.    short i, j;
  21.  
  22.    move( 0, 0); clrtobot();
  23.    for( i = 0; i < rows; i++)
  24.       for( j = 0; map[i][j] != '\0'; j++)
  25.          mapchar( map[i][j], i, j);
  26.    move( MAXROW, 0);
  27.    printw( "Level:      Packets:      Saved:      Moves:             Pushes:");
  28.    displevel();
  29.    disppackets();
  30.    dispsave();
  31.    dispmoves();
  32.    disppushes();
  33.    move( MAXROW+2,0);
  34.    refresh();
  35. }
  36.  
  37. mapchar( c, i, j)
  38. char c;
  39. short i, j;
  40. {
  41.    short offset_row = (MAXROW - rows) / 2;
  42.    short offset_col = MAXCOL - cols;
  43.  
  44.    move( i + offset_row, 2*j + offset_col);     addch( c);
  45.    move( i + offset_row, 2*j + 1 + offset_col); addch( c);
  46. }
  47.  
  48. displevel() {
  49.    move( MAXROW, 7); printw( "%3d", level);
  50. }
  51.  
  52. disppackets() {
  53.    move( MAXROW, 21); printw( "%3d", packets);
  54. }
  55.  
  56. dispsave() {
  57.    move( MAXROW, 33); printw( "%3d", savepack);
  58. }
  59.  
  60. dispmoves() {
  61.    move( MAXROW, 45); printw( "%10d", moves);
  62. }
  63.  
  64. disppushes() {
  65.    move( MAXROW, 65); printw( "%10d", pushes);
  66. }
  67.  
  68. helpmessage() {
  69.    move( MAXROW+2, 0); printw( "Press ? for help.%c", '\007');
  70.    refresh();
  71. #if ATARIST
  72.     get_char();
  73. #else
  74.    input_off();                              /* no input allowed while sleeping */
  75.    sleep( 2);
  76.    input_on();                            /* end raw mode */
  77. #endif
  78.    move( MAXROW+2, 0); deleteln();
  79.    refresh();
  80. }
  81.  
  82. showhelp() {
  83.  
  84.    FILE *helpfile;
  85.    char buf[80];
  86.    short i, ret = 0, endhelp = 0, c;
  87.  
  88.    if( (helpfile = fopen( HELPFILE, "r")) == NULL)
  89.       ret = E_FOPENHELP;
  90.    else {
  91.       input_off();
  92.       move( 0, 0); clrtobot();
  93.       i = 0;
  94.       while( fgets( buf, 80, helpfile) && (! endhelp)) {
  95.         if( strncmp( buf, "+=", 2) == 0) {             /* page eject */
  96.            move( 23, 0);
  97.            addstr( "(Press space to continue, return to exit help)");
  98.            refresh();
  99.            input_on();
  100.            if( (c = get_char()) == 
  101. #if ATARIST
  102. '\r'
  103. #else
  104. '\n'
  105. #endif
  106. )
  107.               endhelp = 1;
  108.            else {
  109.               i = 0;
  110.               move( 0, 0); clrtobot();
  111.               refresh();
  112.               input_off();
  113.            }
  114.         }
  115.         else if( strncmp( buf, "==", 2) == 0) {        /* end of helpfile */
  116.            move( 23, 0);
  117.            addstr( "(Press any key to continue)");
  118.            refresh();
  119.            input_on();
  120.            get_char();
  121.            endhelp = 1;
  122.         }
  123.         else {
  124.            move( i, 0);
  125.            addstr( buf);
  126.            i++;
  127.         }
  128.       }
  129.    }
  130.    return( ret);
  131. }
  132.